/**
 * Created by Administrator on 2017/10/19 0019.
 */

layui.use(['element','form','layer'], function() {
    var form = layui.form;
    var element = layui.element;
    var layer = layui.layer;



    //表单校验
    form.verify({
        oldpassword:function (value, item) {
            if (!/^[\S]{6,12}$/.test(value)){
                return '密码必须6到12位，且不能出现空格';
            }
        },
        password1:function (value, item) {
            if (!/^[\S]{6,12}$/.test(value)){
                return '密码必须6到12位，且不能出现空格';
            }
        }
    })
    form.on('submit(formSubmit)', function(data){
        var val = $("#oldpassword").val();
        var val1 = $("#password1").val();
        var val2 = $("#password2").val();
        $.ajax({
            url:"/user/updatepwd",
            type:"get",
            data:{oldpassword:val,password1:val1,password2:val2},
            dataType:"json",
            async:false,
            success:function (msg) {
                if (msg.code==1){
                   parent.layer.msg("密码修改成功，请重新登录！",{time:2000},function () {
                       parent.location.href = "/";
                   })
                }else{
                    layer.msg(msg.message)
                }
            },
            error:function () {
                console.log("返回异常")
            }
        })
        return false;
    })
})
